from .SSFM_each_span import SSFM_each_span
from .Amplifier import amplifier
from .Amplifier import Amplifier
import numpy as np
from .Parameters import Parameters


def fiber_G652(sig, num_symbols, bits_per_symbol, total_baud,
               up_sampling_factor, sampling_rate, 
               num_spans, span_length, delta_z, alpha, beta2,
               gamma):
    """
    
    :param delta_z: 
    :param alpha: 
    :param beta2: 
    :param gamma: 
    :returns: 
    """
    Signal, Fiber_para, Amplifer_para, PMD_para = Parameters(num_symbols, bits_per_symbol, total_baud,
                                                             up_sampling_factor, sampling_rate,
                                                             num_spans, span_length, delta_z, alpha, beta2, gamma)
    # print(f'刚进入光纤的信号')
    # print(f'sig {sig}')
    # print(f'len of sig {len(sig)}')
    # print(f'sig[0] {sig[0]}')
    # print('_'*50)
    # """"""
    # P_dB = 0
    # power = pow(10, (P_dB / 10)) * 1e-3
    # TX_X = sig[0].reshape(-1)
    # TX_Y = sig[1].reshape(-1)
    # TX_X = np.divide(TX_X, np.sqrt(np.mean(np.square(np.abs(TX_X)))))
    # TX_Y = np.divide(TX_Y, np.sqrt(np.mean(np.square(np.abs(TX_Y)))))
    # TX_X = TX_X * np.sqrt(power)
    # TX_Y = TX_Y * np.sqrt(power)
    # sig = [TX_X, TX_Y]
    # sig = np.expand_dims(sig, axis=2)
    # """"""
    # print(f'第一次处理信号')
    # print(f'sig {sig}')
    # print(f'type of sig {type(sig)}')
    # print(f'len of sig {len(sig)}')
    # print('_'*50)
    # # 更改数据格式
    # sig = np.array(sig)
    # sig = sig.transpose()
    # sig = sig[0]
    # print(f'第二次处理信号')
    # print(f'sig {sig}')
    # print(f'type pf sig {type(sig)}')
    # print(f'len of sig {len(sig)}')
    # print('_'*50)
    # for i in range(Fiber_para['Span']):
        # Fiber_para["span_num"] = i
        # span_num = Fiber_para["span_num"]
    prev_symbols=[sig[1],sig[2]]
    sig=sig[0]
    signal = SSFM_each_span(sig, Signal, Fiber_para, PMD_para)
    # print("第", str(i+1), "Span分步傅里叶完成")  # 输出;将数值转换成字符串
    # print(f'SSFM_each_span -> sig{sig}')
    # print(f'SSFM_each_span -> type of sig{type(sig)}')
    # print(f'SSFM_each_span -> len of sig{len(sig)}')
    # print(f'SSFM_each_span -> sig[0]{sig[0]}')
    # 经过EDFA

    # EDFA_nf = 5
    # sampling_rate = 80000000000.0
    # f_c = 193548387096774.16
    # gain = 10.0
    # sig = amplifier(sig, EDFA_nf, sampling_rate, f_c, gain)
    # sig = Amplifier(sig, Amplifer_para, Signal, Fiber_para)
    # print("第", str(i+1), "Span的Amplifer添加完成")
    # print(f'Amplifier -> sig{sig}')
    # print(f'Amplifier -> len of sig{len(sig)}')
    # print(f'Amplifier -> type of sig{type(sig)}')
    # print(f'Amplifier -> sig[0]{sig[0]}')
    
    # signal = sig
    # signal = np.array(signal)
    # signals_power = [np.mean(np.abs(signal[0:, 0]) ** 2),
    #                     np.mean(np.abs(signal[0:, 1]) ** 2)]

    # # 更改数据格式
    # s1 = np.expand_dims(signal[0:, 0], axis=1)
    # s2 = np.expand_dims(signal[0:, 1], axis=1)
    # signal = [s1, s2]

    return [signal, prev_symbols[0], prev_symbols[1]] 
